from common.base import *


driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.baidu.com')

kw = driver.find_element(By.ID, 'kw')
kw.send_keys('python')
driver.find_element(By.ID, 'su').click()

js1 = 'window.scrollTo(0, 0)'  # 页面顶部
js2 = 'window.scrollTo(0, document.body.scrollHeight)'  # 页面底部
# 滚动到页面底端
# sleep(3)
# driver.execute_script(js2)

js3 = 'window.scrollTo({left:0, top:document.body.scrollHeight, behavior:"smooth"})'   # 丝滑滚动到底部
# 丝滑滚动到页面底端
sleep(3)
driver.execute_script(js3)
# 滑动到顶端
driver.execute_script(js1)
# 聚焦到某个元素位置
sleep(3)
target = driver.find_element(By.XPATH, '//*[@id="8"]/div/div[1]/h3')
driver.execute_script("arguments[0].scrollIntoView();", target)

sleep(5)
driver.quit()
